<div class="config-container">
  <h3>Stage Settings</h3>

  <%= form_for(@stage,
               :as => :stage,
               :url => admin_stage_update_path,
               :html => {:method => "PUT",
                         :id => "stage_edit_form",
                         :onsubmit => "return AjaxForm.jquery_ajax_submit(this, AjaxForm.ConfigFormEditHandler);",
                         :class => "popup_form"}) do |f| %>
    <%= md5_field %>
    <%= hidden_field_tag :pipeline_digest, @pipeline_digest %>
    <%= hidden_field_tag :pipeline_group_name, @pipeline_group_name %>
    <%= hidden_field_tag :pipeline_name, @pipeline.name %>
    <%= render :partial => "admin/shared/global_errors.html", :locals => {:scope => {}} -%>
    <div class="fieldset">
      <div class="form_item_block required">
        <%= required_label(f, :name, 'Stage Name') %>
        <%= f.text_field :name %>
        <%= error_message_on(@stage, "name", :css_class => "form_error") %>
      </div>
      <div class="form_item_block checkbox_row">
        <label>Stage Type:</label>
        <span class="stage_approval contextual_help has_go_tip_right" title="'On Success' option will automatically schedule the stage after the preceding stage completes successfully. The 'Manual' option will require a user to manually trigger the stage. For the first stage in a pipeline, setting type to 'on success' is the same as checking 'Automatic Pipeline Scheduling' on the pipeline config.">&nbsp;</span>
        <%= f.fields_for com.thoughtworks.go.config.StageConfig::APPROVAL, @stage.approval do |approval| %>
          <div class="stage_approval_container">
            <%= approval.radio_button com.thoughtworks.go.config.Approval::TYPE, com.thoughtworks.go.config.Approval::SUCCESS, :id => "auto" %>
            <label for="auto">On Success</label>

            <%= approval.radio_button com.thoughtworks.go.config.Approval::TYPE, com.thoughtworks.go.config.Approval::MANUAL, :id => "manual" %>
            <label for="manual">Manual</label>

            <div id="div_allow_on_success">
              <%= approval.check_box "allowOnlyOnSuccess", {}, "true", "false" %>
              <label for="stage_approval_allowOnlyOnSuccess">Allow Scheduling Only If Previous Stage Succeed</label>
              <span class="stage_approval_allowOnlyOnSuccess contextual_help has_go_tip_right" title="If checked, can be manually triggered only if the previous stage run is successful.">&nbsp;</span>
            </div>

          </div>
          <%= error_message_on(@stage.getApproval(), "type", :css_class => "form_error") %>

          <%= error_message_on(@stage.getApproval(), "type", :css_class => "form_error") %>
        <% end %>
      </div>
      <div class="form_item_block checkbox_row fetch_materials">
        <%= f.check_box :fetchMaterials %>
        <label for="stage_fetchMaterials">Fetch Materials</label>
        <span class="contextual_help has_go_tip_right" title="Perform material updates or checkouts">&nbsp;</span>
        <%= error_message_on(@stage.isFetchMaterials(), "type", :css_class => "form_error") %>
      </div>
      <div class="form_item_block checkbox_row fetch_materials">
        <%= f.check_box com.thoughtworks.go.config.StageConfig::ARTIFACT_CLEANUP_PROHIBITED %>
        <label for="stage_artifactCleanupProhibited">Never Cleanup Artifacts</label>
        <span class="contextual_help has_go_tip_right" title="Never cleanup artifacts for this stage, if purging artifacts is configured at the Server Level">&nbsp;</span>
        <%= error_message_on(@stage.isArtifactCleanupProhibited(), "type", :css_class => "form_error") %>
      </div>
      <div class="form_item_block checkbox_row clean_working_dir">
        <%= f.check_box :cleanWorkingDir %>
        <label for="stage_cleanWorkingDir">Clean Working Directory</label>
        <span class="contextual_help has_go_tip_right" title="Remove all files/directories in the working directory on the agent">&nbsp;</span>
        <%= error_message_on(@stage.isCleanWorkingDir(), "type", :css_class => "form_error") %>
      </div>
      <%= render :partial => 'shared/form_required_message.html', :locals => {:scope => {}} unless @is_config_repo_pipeline %>
    </div>

    <%= render :partial => 'shared/convert_tool_tips.html', :locals => {:scope => {}} %>
    <%= render :partial => "admin/shared/form_submit", :locals => {:scope => {:reset_url => admin_stage_edit_path(:current_tab => "settings")}} unless @is_config_repo_pipeline %>

  <% end %>
</div>
<script type="text/javascript">
  AjaxForm.error_box_selector = '#form_parent';
  jQuery(document).ready(function () {
  });
</script>

